#region Usings
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
#endregion

namespace Import.Lib
{
    public abstract class ExpensesDocument
    {
        #region Readonly & Static Fields
        private readonly DataTable _dataTable;
        private readonly Encoding _encoding;
        private readonly string _fileName;
        #endregion

        #region C'tors
        protected ExpensesDocument(string fileName, Encoding encoding)
        {
            _fileName = fileName;
            _encoding = encoding;
            _dataTable = new DataTable();
        }
        #endregion

        #region Instance Methods
        public void Load()
        {
            using (FileStream stream = new FileStream(FileName, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader streamReader = new StreamReader(stream, Encoding))
                {
                    LoadHeader(streamReader);
                    LoadBody(streamReader);
                }
            }
        }

        protected abstract void LoadBody(TextReader reader);
        protected abstract void LoadHeader(TextReader reader);
        #endregion

        #region Instance Properties
        public Encoding Encoding
        {
            [DebuggerStepThrough]
            get { return _encoding; }
        }

        public string FileName
        {
            [DebuggerStepThrough]
            get { return _fileName; }
        }

        protected DataTable DataTable
        {
            [DebuggerStepThrough]
            get { return _dataTable; }
        }
        #endregion
    }
}